package com.googlecode.cswish.security.type;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

import com.googlecode.cswish.security.Context;


public class RecordRuleSetAnd implements Calculation {

	private List<Calculation> expressList = new ArrayList<Calculation>();
	
	@Override
	public String execute(Context context) {
		if (expressList.size() > 0) {
			StringBuilder sb = new StringBuilder();
			for (Iterator<Calculation> iter = expressList.iterator(); iter.hasNext();) {
				Calculation expression = iter.next();
				
				
				String expressionResult = expression.execute(context);
					
				sb.append(" and (").append(expressionResult).append(")");
			}
			
			// remove the first " and "
			return sb.substring(5);
		} else {
			return "";
		}
	}
	
	public boolean executeBoolean(Context context) {
		return true;
	}
}